/**
 * 
 */
package com.innovationhero.main.client.UX;

import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.logical.shared.HasAttachHandlers;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasAnimation;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * Will provide an IPhone PointNavigationMenu eXperiance for the user 
 * @author InnovationHero
 **/
public class Navigation 
extends Widget // Used to extend Composite but now I changed it to Widget 
implements IdeaUXEventHandler, // My Custom EventHandler Interface  
HasAttachHandlers, HasHandlers, EventListener, HasAnimation, IsWidget // Implemented all MenuBar interfaces http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/MenuBar.html

{
	private static final Widget NavigationWidget = new Navigation();
	
	private TextBox navpoint1 = new TextBox();
	private TextBox navpoint2 = new TextBox();
	private TextBox navpoint3 = new TextBox();
	private TextBox navpoint4 = new TextBox();
	
	
	
	public Navigation(){
	
	}

	/* 
	 * The cool constructor 
	 * 
	 * */
//	@SuppressWarnings("unchecked")
//	public Navigation(HandlerManager eventBus ){
//		// The non Widget Constructor that deals with the RootPanel directly   
//		RootPanel rootPanel = RootPanel.get("Navigation");
//		rootPanel.add(navpoint1,0, 100);
//		rootPanel.add(navpoint2,0, 200);
//		rootPanel.add(navpoint3,0, 300);
//		rootPanel.add(navpoint4,0, 400);
//		eventBus.addHandler(IdeaUXEvent.TYPE, this);
//	}
	
	
	public Navigation(SortedMap navPoints, HandlerManager eventBus) {		
		NavigationWidget(navPoints, eventBus);
	}

	public Widget NavigationWidget(final SortedMap navPoints, HandlerManager eventBus ){

		// This Navigation should be a Widget class,  
		
		
		

		// Get the number of points in the navigation menu and create the navigation point image and set each one its values using a while loop
		Iterator iterator = navPoints.keySet().iterator();
		  while (iterator.hasNext()) {
		  final Object key = iterator.next();
		//  System.out.println("key : " + key + " value :" + navPoints.get(key));
		  final Image navPoint = new Image(navPoints.get(key).toString());

		  
		  navPoint.addMouseOverHandler(new MouseOverHandler(){   //NICE INLINE HANDLER THAT I SHOULD FOLLOW LATER 
			@Override
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
				navPoint.setUrl("http://technabob.com/blog/wp-content/uploads/2006/12/apple_logo-full.thumbnail.jpg");
				
				
			}
		});
navPoint.addMouseOutHandler(new MouseOutHandler() {
	
	@Override
	public void onMouseOut(MouseOutEvent event) {
		// TODO Auto-generated method stub
		navPoint.setUrl("http://a0.twimg.com/profile_images/136103132/619239_wedding_flower_normal.jpg");
	}
});

navPoint.addClickHandler(new ClickHandler() {
	
	@Override
	public void onClick(ClickEvent event) {
	
		
	}
});
		  
			RootPanel rootPanel = RootPanel.get("PointNavigationBar");

	rootPanel.add(navPoint);
eventBus.addHandler(IdeaUXEvent.TYPE, this);  
		  }
		
		return NavigationWidget;
	}
	
//	NEffectPanel example1EP = new NEffectPanel();  
//	Fade theFade = new Fade();  
//	Image img = new Image("ski.png");  
//	example1EP.add(img);  
//	example1EP.addEffect(theFade);  
//	RootPanel.get().add(example1EP);
//	
//	

	@Override
	public void mouseOver(IdeaUXEvent event) {
		
		MouseOverHandler navpoint1handler = new MouseOverHandler() {
			
			@Override
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
		// navpoint1.setText("I am hit");
				
			}
		};;;
		// Make the Navigation widget shine 
		navpoint1.addMouseOverHandler(navpoint1handler);
		MouseOverHandler navpoint2handler = new MouseOverHandler() {
			
			@Override
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
				navpoint2.setText("I am hit");
			}
		};;;
		navpoint2.addMouseOverHandler(navpoint2handler);
		MouseOverHandler navpoint3handler = new MouseOverHandler() {
			
			@Override
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
				navpoint3.setText("I am hit");
			}
		};;;
		navpoint3.addMouseOverHandler(navpoint3handler);
		MouseOverHandler navpoint4handler = new MouseOverHandler() {
			
			@Override
			public void onMouseOver(MouseOverEvent event) {
				// TODO Auto-generated method stub
				navpoint4.setText("I am hit");
			}
		};;;
		navpoint4.addMouseOverHandler(navpoint4handler);
		// Make the the background of the webapp change, or change the whole theme of the app into somthing diff
		
		
		// Logic of If-Else Statment to make a diff effect for each mouseOver on each navigation Point,
		// 1st point Make the current easeOut to the left and Options easeIn from the right
		// 2nd point Make the current easeOut to the 
	}

	@Override
	public void mouseOut(IdeaUXEvent event) {

		MouseOutHandler navpoint1handler = new MouseOutHandler() {
			
			@Override
			public void onMouseOut(MouseOutEvent event) {
				// TODO Auto-generated method stub
		navpoint1.setText("I am out");		
			}
		};;;
 
		navpoint1.addMouseOutHandler(navpoint1handler);
		
		// Number 2 
		MouseOutHandler navpoint2handler = new MouseOutHandler() {
			
			@Override
			public void onMouseOut(MouseOutEvent event) {
				// TODO Auto-generated method stub
				navpoint2.setText("I am out");
			}
		};;;
		navpoint2.addMouseOutHandler(navpoint2handler);
		
		// Number 3
		MouseOutHandler navpoint3handler = new MouseOutHandler() {
			
			@Override
			public void onMouseOut(MouseOutEvent event) {
				// TODO Auto-generated method stub
				navpoint3.setText("I am out");
			}
		};;;
		navpoint3.addMouseOutHandler(navpoint3handler);
		
		// Number 4
		MouseOutHandler navpoint4handler = new MouseOutHandler() {
			
			@Override
			public void onMouseOut(MouseOutEvent event) {
				// TODO Auto-generated method stub
				navpoint4.setText("I am out");
			}
		};;;
		navpoint4.addMouseOutHandler(navpoint4handler);
		
	}

	@Override
	public boolean isAnimationEnabled() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setAnimationEnabled(boolean enable) {
		// TODO Auto-generated method stub
		
	}
}